﻿using EPiServer.Common;

namespace JoelAbrahamsson.Web.ExtensionMethods
{
    public static class AuthorExtensions
    {
        public static bool HasUrl(this IAuthor author)
        {
            if(!(author is GuestAuthor))
                return false;

            GuestAuthor guestAuthor = (GuestAuthor)author;

            return !string.IsNullOrEmpty(guestAuthor.Url);
        }

        public static string GetUrl(this IAuthor author)
        {
            if (!(author is GuestAuthor))
                return null;

            GuestAuthor guestAuthor = (GuestAuthor)author;

            string url = guestAuthor.Url;

            if(!url.ToLower().StartsWith("http://"))
                url = "http://" + url;

            return url;
        }
    }
}
